package com.xuexiang.xui_lib.component.imageview.nine;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.element.Element;
import ohos.agp.render.BlendMode;
import ohos.agp.render.ColorMatrix;
import ohos.app.Context;
import ohos.multimodalinput.event.TouchEvent;

/**
 * 九宫图图片
 *
 * @author liuluming
 * @since 2021-04-08
 */
public class GridImageView extends Image implements Component.TouchEventListener {

    public GridImageView(Context context, AttrSet attrs) {
        super(context, attrs);
    }

    public GridImageView(Context context) {
        super(context);
    }

    @Override
    public boolean onTouchEvent(Component component, TouchEvent touchEvent) {
        switch (touchEvent.getAction()) {
            case TouchEvent.PRIMARY_POINT_DOWN:
                Element drawable = getImageElement();
                ColorMatrix colorMatrix =new ColorMatrix();
                drawable.setColorMatrix(colorMatrix);
                drawable.setStateColorMode(BlendMode.MULTIPLY);
                break;
            case TouchEvent.PRIMARY_POINT_UP:
                Element drawableUp = getImageElement();
                if (drawableUp != null) {
                    drawableUp.clearColorMatrix();
                }
                break;
            default:
                break;
        }
        return false;
    }
}